
//验证double类型
function checkDouble(curcy){
	var patFinal=/^\d+(\.?\d+)?$/;
	var patMid=/^\d+\.$/;
	if(curcy==null || curcy=="" ){
		return false;
	}else if(patMid.test(curcy)==true){//匹配0. 1. 2.等
		return true;
	}else if(patFinal.test(curcy)==true){
		return true;
	}
}
//验证余额
function checkCurcy(exchange,balance){
	if(parseFloat(exchange)<=parseFloat(balance)){
		return true;
	}else{
		return false;
	}
}
//兑换人民币
function rmbChange(balanceRmb){
	var rmb=$("#rmb_exchange").val();
	if(checkDouble(rmb)==true){
		if(checkCurcy(rmb,balanceRmb)){
			$.post("curcyChange.htm",{curcy:rmb,changeType:'rmb'},function(data){
	  			$("#change_GGB").html(data);
	  		});
		}else{
			alert("余额不足");
			$("#rmb_exchange").val("");
	        $("#change_GGB").html(0);
		}
	}else{
		alert("请输入数字金额");
		$("#rmb_exchange").val("");
        $("#change_GGB").html(0);
	}
}

function exchangeGGB(div_load_id,balanceRmb){
	var rmb=$("#rmb_exchange").val();
	if(checkDouble(rmb) && checkCurcy(rmb,balanceRmb)){
		$.post("exchangeGGB.htm",{rmb:rmb},function(res){
			if(res=="success"){
				$("#"+div_load_id).load("balance.htm?tranPage="+div_load_id);
			}
		});
	}else{
		alert("请输入数字金额");
		$("#rmb_exchange").val("");
	}
}
function exchangeAllGGB(div_load_id,balanceRmb){
	if(checkDouble(balanceRmb)){
		$.post("exchangeGGB.htm",{rmb:balanceRmb},function(res){
			if(res=="success"){
				$("#"+div_load_id).load("balance.htm?tranPage="+div_load_id);
			}else{
				alert("兑换失败");
			}
		});
	}else{
		alert("请输入数字金额");
		$("#rmb_exchange").val("");
	}
}


//兑换果果币
function ggbChange(balanceGgb){
	var ggb=$("#ggb_exchange").val();
	if(checkDouble(ggb)==true){
		if(checkCurcy(ggb,balanceGgb)){
			$.post("curcyChange.htm",{curcy:ggb,changeType:'ggb'},function(data){
	  			$("#change_RMB").html(data);
	  		});
		}else{
			alert("余额不足");
			$("#ggb_exchange").val("");
	        $("#change_RMB").html(0);
		}
	}else{
		alert("请输入数字金额");
		$("#ggb_exchange").val("");
        $("#change_RMB").html(0);
	}
}

function exchangeRMB(div_load_id,balanceGgb){
	var ggb=$("#ggb_exchange").val();
	if(checkDouble(ggb) && checkCurcy(ggb,balanceGgb)){
		$.post("exchangeRMB.htm",{ggb:ggb},function(res){
			if(res=="success"){
				$("#"+div_load_id).load("balance.htm?tranPage="+div_load_id);
			}
		});
	}else{
		alert("请输入数字金额");
		$("#ggb_exchange").val("");
	}
}
function exchangeAllRMB(div_load_id,balance){
	if(checkDouble(balance)){
		$.post("exchangeRMB.htm",{ggb:balance},function(res){
			if(res=="success"){
				$("#"+div_load_id).load("balance.htm?tranPage="+div_load_id);
			}else{
				alert("兑换失败");
			}
		});
	}else{
		alert("请输入数字金额");
		$("#ggb_exchange").val("");
	}
}



